﻿$(function () {
    var icon = "<i class='fa fa-times-circle'></i> ";
    var state = $('#State').val();
    var validator = $("#mainForm").validate({
        rules: {
            Remark: {
                required: true,
                minlength: 2
            },
            Amount: {
                required: true,
                number: true
            }
        },
        messages: {
            Remark: {
                required: icon + "请输入费用说明",
                minlength: icon + "名称必须两个字符以上"
            },
            Amount: {
                required: icon + "请输入金额",
                number: icon + "必须输入数字"
            }
        },
        submitHandler: function (form) {
            //进行ajax传值
            $.ajax({
                url: state == 1 ? "/Account/Brokerage/ConfirmBrokerageAsync" : "/Account/Brokerage/AuditingBrokerageAsync",
                type: "post",
                dataType: "json",
                data: $('#mainForm').serialize(),
                success: function (data) {
                    //Info,Success,Warning,Error
                    var type = data.type;
                    if (type == 1) {
                        layer.msg(data.content, { icon: 6, time: 2000 },
                            function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                            });

                    } else {
                        layer.msg(data.content, { icon: 5, time: 2000 });
                    }
                }
            });
        }
    });
    initTable();
});
var $table = $('#table');


function initTable() {
    $table.bootstrapTable({
        url: '/Account/Brokerage/GetBrokerageGroupLevelList',            //数据来源地址
        method: 'post',                     //数据请求方式
        striped: true,                      //是否显示行间隔色
        cache: false,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
        pagination: false,                   //是否启用分页
        sidePagination: 'server',           //在服务器端分页
        queryParams: queryParams,           //传递参数
        pageNumber: 1,                      //初始化加载第一页，默认第一页
        pageSize: 20,                       //每页的记录行数（*）
        pageList: [10, 20, 30, 40, 50],     //可供选择的每页的行数（*）
        clickToSelect: true,                //是否启用点击选中行
        //toolbar: "#tableToolBar",
        height: getHeight(),
        search: false,
        showRefresh: false,
        showColumns: false,
        toolbar: '',
        iconSize: 'outline',
        icons: {
            refresh: 'glyphicon-repeat',
            columns: 'glyphicon-list'
        },
        toolbar: '',
        columns: [ {
            field: 'brokerageGroupName',
            title: '佣金分组名称',
            align: 'center',
        }, {
            field: 'achievement',
            title: '业绩',
            align: 'center',
        }, {
            field: 'percentage',
            title: '提成',
            align: 'center',
        }, {
            field: 'award',
            title: '奖金',
            align: 'center',
        }, {
            field: 'totalPrice',
            title: '成交价',
            align: 'center',
        }, {
            field: 'amount',
            title: '佣金',
            align: 'center',
        }]
    });
}

//查询的参数
var queryParams = function (params) {
    var temp = {
        ModuleID: $('#ModuleID').val(),
        BrokerageTypeID: $('#BrokerageTypeID').val(),
        RunningsID: $('#RunningsID').val(),
    };
    console.log(temp);
    console.log(params);
    return temp;
};
function getHeight() {
    return $(window).height() - 150;
};